package com.ruoyi.common.utils;

public class Result {


    private boolean success;
    private String msg;
    private Object obj;

    public Result() {}

    public Result(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }
    public Result(boolean success) {
        this.success = success;
    }

    public Result(boolean success, Object obj) {
        this.success = success;
        this.obj = obj;
    }
    public boolean isSuccess() {
        return this.success;
    }
    public void setSuccess(boolean success) {
        this.success = success;
    }
    public String getMsg() {
        return this.msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getObj() {
        return this.obj;
    }
    public void setObj(Object obj) {
        this.obj = obj;
    }

    public static Result ok() {
        return new Result(true);
    }
    public static Result fail(String msg) {
        return new Result(false, msg);
    }

    public static Result check(Object obj) {
        return new Result(true, obj);
    }

    public static String checkJson(Object obj) {
        return JsonUtils.getJsonStr(new Result(true, obj));
    }
    public static String okJson() {
        return JsonUtils.getJsonStr(new Result(true));
    }
    public static String failJson(String msg) {
        return JsonUtils.getJsonStr(new Result(false, msg));
    }
    public static String ResultJson(Result result) {
        return JsonUtils.getJsonStr(result);
    }
    public static String failJson() {
        return JsonUtils.getJsonStr(new Result(false, "操作异常！"));
    }
    public static String failJson(Object obj) {
        return JsonUtils.getJsonStr(new Result(false, obj));
    }

    public String toString() {
        return "Result [success=" + this.success + ", msg=" + this.msg + "]";
    }

    public static String toJsonBySuccess(boolean success) {
        if (success) {
            return okJson();
        }
        return failJson();
    }
}
